<?php

/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
class omeanalysts_ctl_analysis_lmreport extends desktop_controller
{

    var $workground = 'omeanalysts_ctl_analysis_lmreport';
    var $pagelimit = 10;

    public function __construct($app)
    {
        parent::__construct($app);
        header("cache-control: no-store, no-cache, must-revalidate");
    }

    function index()
    {
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $paybegin = strtotime($_POST['paybegin_date']);
        $payend = strtotime($_POST['payend_date']);
        $_POST['paybegin_date'] = $_POST['paybegin_date'] . ' ' . $_POST['_DTIME_']['H']['paybegin_date'] . ':' . $_POST['_DTIME_']['M']['paybegin_date'];
        $paybegin = strtotime($_POST['paybegin_date']);
        $_POST['payend_date'] = $_POST['payend_date'] . ' ' . $_POST['_DTIME_']['H']['payend_date'] . ':' . $_POST['_DTIME_']['M']['payend_date'];
        $payend = strtotime($_POST['payend_date']);
        $_POST['paybegin_date'] = $_POST['paybegin_date'] ? $_POST['paybegin_date'] : $paybegin_date;
        $_POST['payend_date'] = $_POST['payend_date'] ? $_POST['payend_date'] : $payend_date;
        if ($_POST['paybegin_date']) {
            $_POST['paybegin_date'] = strtotime($_POST['paybegin_date']);
            $_POST['paybegin_date'] = date("Y-m-d H:i:s", $_POST['paybegin_date']);
        }
        if ($_POST['payend_date']) {
            $_POST['payend_date'] = strtotime($_POST['payend_date']);
            $_POST['payend_date'] = date("Y-m-d H:i:s", $_POST['payend_date']);
        }
        $_POST['shop'] = $_POST['shop'] ? $_POST['shop'] : $shopIds;

        //供应商
        $clearingtable['shop_id'] = $_POST['shop'];
        $clearingtable['conditiondate_id'] = $_POST['conditiondate'];
        $conditiondate_id = $_POST['conditiondate'];
        $shop_obj = app::get('ome')->model('shop');
        $deliverycomp_obj = app::get('wms')->model('deliverycomp');
        $shop_list = $shop_obj->getList('shop_id,name', $where, 0, -1, 'shop_id asc');

        //获取客户名称 group by
        $customerList=$deliverycomp_obj->getCustomerList($this->shopIds);
        $this->pagedata['customerList'] = $customerList;
        $clearingtable['customer_name']=$_POST['customer_name'];



        $conditiondate = array(
            0 => array('id' => '0', 'name' => '付款日期',),
            1 => array('id' => '1', 'name' => '发货日期',),
        );
        $this->pagedata['shop'] = $shop_list;
        $this->pagedata['conditiondate'] = $conditiondate;

        #统计日期
        if ($_POST['paybegin_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {

            $paybegin_date = strtotime(date("Y-m-d H:i:s", time()));
            $clearingtable['paybegin_date'] = $paybegin_date;
        } else {
            $paybegin_date = $_POST['paybegin_date'];
            $clearingtable['paybegin_date'] = $paybegin;
        }
        if ($_POST['payend_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {
            $payend_date = strtotime(date("Y-m-d H:i:s", time()));
            $clearingtable['payend_date'] = $payend_date;
        } else {
            $payend_date = $_POST['payend_date'];
            $clearingtable['payend_date'] = $payend;
        }
        $comp_data = $deliverycomp_obj->GetOrderSumData($_POST['shop'],$_POST['customer_name'],$conditiondate_id, $paybegin_date, $payend_date);
        $this->pagedata['comp_data'] = $comp_data;
        $this->pagedata['clearingtable'] = $clearingtable;
        $this->page('analysis/lmreport/reportshow.html');
    }

    function index_pay()
    {
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $paybegin = strtotime($_POST['paybegin_date']);
        $payend = strtotime($_POST['payend_date']);

        $_POST['paybegin_date'] = $_POST['paybegin_date'] . ' ' . $_POST['_DTIME_']['H']['paybegin_date'] . ':' . $_POST['_DTIME_']['M']['paybegin_date'];
        $paybegin = strtotime($_POST['paybegin_date']);
        $_POST['payend_date'] = $_POST['payend_date'] . ' ' . $_POST['_DTIME_']['H']['payend_date'] . ':' . $_POST['_DTIME_']['M']['payend_date'];
        $payend = strtotime($_POST['payend_date']);
        $_POST['paybegin_date'] = $_POST['paybegin_date'] ? $_POST['paybegin_date'] : $paybegin_date;
        $_POST['payend_date'] = $_POST['payend_date'] ? $_POST['payend_date'] : $payend_date;
        if ($_POST['paybegin_date']) {
            $_POST['paybegin_date'] = strtotime($_POST['paybegin_date']);
            $_POST['paybegin_date'] = date("Y-m-d H:i:s", $_POST['paybegin_date']);
        }
        if ($_POST['payend_date']) {
            $_POST['payend_date'] = strtotime($_POST['payend_date']);
            $_POST['payend_date'] = date("Y-m-d H:i:s", $_POST['payend_date']);
        }


        $_POST['dlybegin_date'] = $_POST['dlybegin_date'] . ' ' . $_POST['_DTIME_']['H']['dlybegin_date'] . ':' . $_POST['_DTIME_']['M']['dlybegin_date'];

        $_POST['dlyend_date'] = $_POST['dlyend_date'] . ' ' . $_POST['_DTIME_']['H']['dlyend_date'] . ':' . $_POST['_DTIME_']['M']['dlyend_date'];
        $_POST['dlyend_date'] = $_POST['dlyend_date'] ? $_POST['dlyend_date'] : $dlyend_date;
        if ($_POST['dlybegin_date']) {
            $_POST['dlybegin_date'] = strtotime($_POST['dlybegin_date']);
            $_POST['dlybegin_date'] = date("Y-m-d H:i:s", $_POST['dlybegin_date']);
        }
        if ($_POST['dlyend_date']) {
            $_POST['dlyend_date'] = strtotime($_POST['dlyend_date']);
            $_POST['dlyend_date'] = date("Y-m-d H:i:s", $_POST['dlyend_date']);
        }

        $_POST['shop'] = $_POST['shop'] ? $_POST['shop'] : $shopIds;

        //供应商
        $clearingtable['shop_id'] = $_POST['shop'];
        $clearingtable['conditiondate_id'] = $_POST['conditiondate'];
        $shop_obj = app::get('ome')->model('shop');
        $shop_list = $shop_obj->getList('shop_id,name', $where, 0, -1, 'shop_id asc');

        $conditiondate = array(
            0 => array('id' => '0', 'name' => '付款日期',),
        );
        $this->pagedata['shop'] = $shop_list;
        $this->pagedata['conditiondate'] = $conditiondate;
        #统计日期
        if ($_POST['paybegin_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {

            $begin_time = strtotime(date("Y-m-d", time())) - 118800 + 1800;
            $clearingtable['paybegin_date'] = $begin_time;
        } else {
            $paybegin_date = $_POST['paybegin_date'];
            $clearingtable['paybegin_date'] = $paybegin;
        }
        if ($_POST['payend_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {
            $begin_time = strtotime(date("Y-m-d", time())) - 32400 + 1800;
            $clearingtable['payend_date'] = $begin_time;
        } else {
            $payend_date = $_POST['payend_date'];
            $clearingtable['payend_date'] = $payend;
        }
        if (!$_POST['dlybegin_date'] || $_POST['dlybegin_date'] == '1970-01-01 08:00:00') {
            $begin_time = strtotime(date("Y-m-d", time())) - 118800 + 1800;
            $clearingtable['dlybegin_date'] = $begin_time;
        } else {
            $dlybegin_date = strtotime($_POST['dlybegin_date']);
            $clearingtable['dlybegin_date'] = strtotime($_POST['dlybegin_date']);
        }
        if (!$_POST['dlyend_date'] || $_POST['dlyend_date'] == '1970-01-01 08:00:00') {
            $dlyend_date = strtotime(date("Y-m-d", time()));
            $clearingtable['dlyend_date'] = strtotime(date("Y-m-d", $dlyend_date));
        } else {
            $dlyend_date = strtotime($_POST['dlyend_date']);
            $clearingtable['dlyend_date'] = strtotime($_POST['dlyend_date']);
        }
        $deliverycomp_obj = app::get('wms')->model('deliverycomp');
        $conditiondate = $_POST['conditiondate'] ? $_POST['conditiondate'] : 0;
        //获取客户名称 group by
        $customerList=$deliverycomp_obj->getCustomerList($this->shopIds);

        $this->pagedata['customerList'] = $customerList;
        $clearingtable['customer_name']=$_POST['customer_name'];
        $comp_data = $deliverycomp_obj->GetOrderSumData_detail($_POST['shop'],$_POST['customer_name'], $conditiondate, $paybegin_date, $payend_date, $dlybegin_date, $dlyend_date);
        $this->pagedata['comp_data'] = $comp_data;
        $this->pagedata['clearingtable'] = $clearingtable;

        $this->page('analysis/lmreport/reportshow_detail.html');
    }

    function report_pay()
    {

        $paybegin_date = substr($_GET['paybegin_date'], 0, 10);
        $payend_date = substr($_GET['payend_date'], 0, 10);
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $_GET['shop'] = $_GET['shop'] ? $_GET['shop'] : $shopIds;

        set_time_limit(600);
        $deliverycomp_obj = app::get('wms')->model('deliverycomp');
        $conditiondate = $_GET['conditiondate'] ? $_GET['conditiondate'] : 0;
        $paybegin_date = date("Y-m-d H:i:s", $paybegin_date);
        $payend_date = date("Y-m-d H:i:s", $payend_date);
        $comp_data = $deliverycomp_obj->GetOrderSumData_detail($_GET['shop'],$_GET['customer_name'], $conditiondate, $paybegin_date, $payend_date);

        include_once ROOT_DIR . "/custom/lib/phpExcel.php";

        $excel = new phpExcel();
        $excel->addHeader(array(
            '店铺', '货号', '货品名称'
        , '单位', '订单量', '备货量', '打印面单量'
        , '发货量', '未发量', '退款量'
        ));
        if ($comp_data) {
            $data_xls = array();
            $qty_sum = $qty1_sum = $print_nums = $qty2_sum = $qty3_sum = $qty4_sum = 0;

            foreach ($comp_data as $val) {
                $qty_sum += $val['qty'];
                $qty1_sum += $val['qty1'];
                $print_nums += $val['print_nums'];
                $qty2_sum += $val['qty2'];
                $qty3_sum += $val['qty3'];
                $qty4_sum += $val['qty4'];

                $data_xls[] = array(
                    $val['shop_name'],
                    $val['material_bn'],
                    $val['material_name'],
                    $val['unit'],
                    $val['qty'] ? $val['qty'] : 0,
                    $val['qty1'] ? $val['qty1'] : 0,
                    $val['print_nums'] ? $val['print_nums'] : 0,
                    $val['qty2'] ? $val['qty2'] : 0,
                    $val['qty3'] ? $val['qty3'] : 0,
                    $val['qty4'] ? $val['qty4'] : 0
                );
            }
        }
        $data_xls[] = array(
            '总数：',
            '',
            '',
            '',
            $qty_sum,
            $qty1_sum,
            $print_nums,
            $qty2_sum,
            $qty3_sum,
            $qty4_sum
        );
        $excel->addBody(
            $data_xls
        );

        $excel->downLoad();
        exit;
    }

    function index_orderform()
    {
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $paybegin = strtotime($_POST['paybegin_date']);
        $payend = strtotime($_POST['payend_date']);

        $_POST['paybegin_date'] = $_POST['paybegin_date'] . ' ' . $_POST['_DTIME_']['H']['paybegin_date'] . ':' . $_POST['_DTIME_']['M']['paybegin_date'];
        $paybegin = strtotime($_POST['paybegin_date']);
        $_POST['payend_date'] = $_POST['payend_date'] . ' ' . $_POST['_DTIME_']['H']['payend_date'] . ':' . $_POST['_DTIME_']['M']['payend_date'];
        $payend = strtotime($_POST['payend_date']);
        $_POST['paybegin_date'] = $_POST['paybegin_date'] ? $_POST['paybegin_date'] : $paybegin_date;
        $_POST['payend_date'] = $_POST['payend_date'] ? $_POST['payend_date'] : $payend_date;
        if ($_POST['paybegin_date']) {
            $_POST['paybegin_date'] = strtotime($_POST['paybegin_date']);
            $_POST['paybegin_date'] = date("Y-m-d H:i:s", $_POST['paybegin_date']);
        }
        if ($_POST['payend_date']) {
            $_POST['payend_date'] = strtotime($_POST['payend_date']);
            $_POST['payend_date'] = date("Y-m-d H:i:s", $_POST['payend_date']);
        }
        $_POST['dlybegin_date'] = $_POST['dlybegin_date'] . ' ' . $_POST['_DTIME_']['H']['dlybegin_date'] . ':' . $_POST['_DTIME_']['M']['dlybegin_date'];
        $_POST['dlyend_date'] = $_POST['dlyend_date'] . ' ' . $_POST['_DTIME_']['H']['dlyend_date'] . ':' . $_POST['_DTIME_']['M']['dlyend_date'];
        $_POST['dlyend_date'] = $_POST['dlyend_date'] ? $_POST['dlyend_date'] : $dlyend_date;
        if ($_POST['dlybegin_date']) {
            $_POST['dlybegin_date'] = strtotime($_POST['dlybegin_date']);
            $_POST['dlybegin_date'] = date("Y-m-d H:i:s", $_POST['dlybegin_date']);
        }
        if ($_POST['dlyend_date']) {
            $_POST['dlyend_date'] = strtotime($_POST['dlyend_date']);
            $_POST['dlyend_date'] = date("Y-m-d H:i:s", $_POST['dlyend_date']);
        }

        $_POST['shop'] = $_POST['shop'] ? $_POST['shop'] : $shopIds;

        //供应商
        $clearingtable['shop_id'] = $_POST['shop'];
        $clearingtable['conditiondate_id'] = $_POST['conditiondate'];
        $shop_obj = app::get('ome')->model('shop');
        $shop_list = $shop_obj->getList('shop_id,name', $where, 0, -1, 'shop_id asc');

        $conditiondate = array(
            0 => array('id' => '0', 'name' => '备货日期',),
        );
        $this->pagedata['shop'] = $shop_list;
        $this->pagedata['conditiondate'] = $conditiondate;
        #统计日期
        if ($_POST['paybegin_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {

            $begin_time = strtotime(date("Y-m-d", time())) - 118800 + 1800;
            $clearingtable['paybegin_date'] = $begin_time;
        } else {
            $paybegin_date = $_POST['paybegin_date'];
            $clearingtable['paybegin_date'] = $paybegin;
        }
        if ($_POST['payend_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {
            $begin_time = strtotime(date("Y-m-d", time())) - 32400 + 1800;
            $clearingtable['payend_date'] = $begin_time;
        } else {
            $payend_date = $_POST['payend_date'];
            $clearingtable['payend_date'] = $payend;
        }

        if (!$_POST['dlybegin_date'] || $_POST['dlybegin_date'] == '1970-01-01 08:00:00') {
            $begin_time = strtotime(date("Y-m-d", time())) - 118800 + 1800;
            $clearingtable['dlybegin_date'] = $begin_time;
        } else {
            $dlybegin_date = strtotime($_POST['dlybegin_date']);
            $clearingtable['dlybegin_date'] = strtotime($_POST['dlybegin_date']);
        }
        if (!$_POST['dlyend_date'] || $_POST['dlyend_date'] == '1970-01-01 08:00:00') {
            $dlyend_date = strtotime(date("Y-m-d", time()));
            $clearingtable['dlyend_date'] = strtotime(date("Y-m-d", $dlyend_date));
        } else {
            $dlyend_date = strtotime($_POST['dlyend_date']);
            $clearingtable['dlyend_date'] = strtotime($_POST['dlyend_date']);
        }

        $deliverycomp_obj = app::get('wms')->model('deliverycomp');
        $customerList=$deliverycomp_obj->getCustomerList($this->shopIds);
        $this->pagedata['customerList'] = $customerList;
        $clearingtable['customer_name']=$_POST['customer_name'];
        $conditiondate = $_POST['conditiondate'] ? $_POST['conditiondate'] : 0;
        $comp_data = $deliverycomp_obj->GetOrderSumData_orderform($_POST['shop'], $_POST['customer_name'],$conditiondate, $paybegin_date, $payend_date, $dlybegin_date, $dlyend_date);
        $this->pagedata['comp_data'] = $comp_data;
        $this->pagedata['clearingtable'] = $clearingtable;

        $this->page('analysis/lmreport/reportshow_orderform.html');
    }

    function report_orderform()
    {
        $paybegin_date = substr($_GET['paybegin_date'], 0, 10);
        $payend_date = substr($_GET['payend_date'], 0, 10);
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $_GET['shop'] = $_GET['shop'] ? $_GET['shop'] : $shopIds;

        set_time_limit(600);
        $deliverycomp_obj = app::get('wms')->model('deliverycomp');
        $conditiondate = $_GET['conditiondate'] ? $_GET['conditiondate'] : 0;
        $paybegin_date = date("Y-m-d H:i:s", $paybegin_date);
        $payend_date = date("Y-m-d H:i:s", $payend_date);
        $comp_data = $deliverycomp_obj->GetOrderSumData_orderform($_GET['shop'], $_GET['customer_name'],$conditiondate, $paybegin_date, $payend_date);

        include_once ROOT_DIR . "/custom/lib/phpExcel.php";

        $excel = new phpExcel();
        $excel->addHeader(array(
            '店铺', '货号', '货品名称'
        , '单位', '订单量', '备货量', '打印面单量'
        , '发货量', '未发量', '退款量'
        ));
        if ($comp_data) {
            $data_xls = array();
            $qty_sum = $qty1_sum = $print_nums = $qty2_sum = $qty3_sum = $qty4_sum = 0;

            foreach ($comp_data as $val) {
                $qty_sum += $val['qty'];
                $qty1_sum += $val['qty1'];
                $print_nums += $val['print_nums'];
                $qty2_sum += $val['qty2'];
                $qty3_sum += $val['qty3'];
                $qty4_sum += $val['qty4'];

                $data_xls[] = array(
                    $val['shop_name'],
                    $val['material_bn'],
                    $val['material_name'],
                    $val['unit'],
                    $val['qty'] ? $val['qty'] : 0,
                    $val['qty1'] ? $val['qty1'] : 0,
                    $val['print_nums'] ? $val['print_nums'] : 0,
                    $val['qty2'] ? $val['qty2'] : 0,
                    $val['qty3'] ? $val['qty3'] : 0,
                    $val['qty4'] ? $val['qty4'] : 0
                );
            }
        }
        $data_xls[] = array(
            '总数：',
            '',
            '',
            '',
            $qty_sum,
            $qty1_sum,
            $print_nums,
            $qty2_sum,
            $qty3_sum,
            $qty4_sum
        );
        $excel->addBody(
            $data_xls
        );

        $excel->downLoad();
        exit;
    }

    function report()
    {
        $paybegin_date = substr($_GET['paybegin_date'], 0, 10);
        $payend_date = substr($_GET['payend_date'], 0, 10);
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $_GET['shop'] = $_GET['shop'] ? $_GET['shop'] : $shopIds;

        set_time_limit(600);
        $shop_obj = app::get('wms')->model('deliverycomp');
        $conditiondate = $_GET['conditiondate'] ? $_GET['conditiondate'] : 0;
        $paybegin_date = date("Y-m-d H:i:s", $paybegin_date);
        $payend_date = date("Y-m-d H:i:s", $payend_date);
        $comp_data = $shop_obj->GetOrderSumData($_GET['shop'],$_GET['customer_name'],$conditiondate, $paybegin_date, $payend_date);

        include_once ROOT_DIR . "/custom/lib/phpExcel.php";

        $excel = new phpExcel();
        $excel->addHeader(array(
            '店铺', '货号', '货品名称'
        , '单位', '订单量', '备货量', '打印面单量'
        , '发货量', '未发量', '退款量'
        ));
        if ($comp_data) {
            $data_xls = array();
            $qty_sum = $qty1_sum = $print_nums = $qty2_sum = $qty3_sum = $qty4_sum = 0;

            foreach ($comp_data as $val) {
                $qty_sum += $val['qty'];
                $qty1_sum += $val['qty1'];
                $qty2_sum += $val['qty2'];
                $print_nums += $val['print_nums'];
                $qty3_sum += $val['qty3'];
                $qty4_sum += $val['qty4'];

                $data_xls[] = array(
                    $val['shop_name'],
                    $val['material_bn'],
                    $val['material_name'],
                    $val['unit'],
                    $val['qty'] ? $val['qty'] : 0,
                    $val['qty1'] ? $val['qty1'] : 0,
                    $val['print_nums'] ? $val['print_nums'] : 0,
                    $val['qty2'] ? $val['qty2'] : 0,
                    $val['qty3'] ? $val['qty3'] : 0,
                    $val['qty4'] ? $val['qty4'] : 0
                );
            }
        }
        $data_xls[] = array(
            '总数：',
            '',
            '',
            '',
            $qty_sum,
            $qty1_sum,
            $print_nums,
            $qty2_sum,
            $qty3_sum,
            $qty4_sum
        );
        $excel->addBody(
            $data_xls
        );

        $excel->downLoad();
        exit;
    }


    function index_test()
    {
        set_time_limit(0);
        list($usec, $sec) = explode(" ", microtime());
        echo date('Y-m-d H:i:s', $sec) . " " . $usec . "<hr/>";
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $_POST['paybegin_date'] = $_POST['paybegin_date'] ? $_POST['paybegin_date'] : $paybegin_date;
        $_POST['payend_date'] = $_POST['payend_date'] ? $_POST['payend_date'] : $payend_date;
        if ($_POST['paybegin_date']) {
            $_POST['paybegin_date'] = strtotime($_POST['paybegin_date']);
            $_POST['paybegin_date'] = date("Y-m-d", $_POST['paybegin_date']);
        }
        if ($_POST['payend_date']) {
            $_POST['payend_date'] = strtotime($_POST['payend_date']);
            $_POST['payend_date'] = date("Y-m-d", $_POST['payend_date']);
        }
        $_POST['shop'] = $_POST['shop'] ? $_POST['shop'] : $shopIds;

        //供应商
        $clearingtable['shop_id'] = $_POST['shop'];
        $clearingtable['conditiondate_id'] = $_POST['conditiondate'];
        $shop_obj = app::get('ome')->model('shop');

        $shop_list = $shop_obj->getList('shop_id,name', $where, 0, -1, 'shop_id asc');

        $conditiondate = array(
            0 => array('id' => '0', 'name' => '付款日期',),
            1 => array('id' => '1', 'name' => '发货日期',),
        );
        $this->pagedata['shop'] = $shop_list;
        $this->pagedata['conditiondate'] = $conditiondate;

        #统计日期
        $clearingtable['paybegin_date'] = $_POST['paybegin_date'] ? $_POST['paybegin_date'] : date("Y-m-d", time());
        $clearingtable['payend_date'] = $_POST['payend_date'] ? $_POST['payend_date'] : date("Y-m-d", time());
        $shop_obj = app::get('wms')->model('deliverycomp');
        $conditiondate = $_POST['conditiondate'] ? $_POST['conditiondate'] : 0;
        $paybegin_date = $_POST['paybegin_date'] ? $_POST['paybegin_date'] : date("Y-m-d", time());
        $payend_date = $_POST['payend_date'] ? $_POST['payend_date'] : date("Y-m-d", time());
        $comp_data = $shop_obj->GetOrderSumData_test4($_POST['shop'], $conditiondate, $paybegin_date, $payend_date);
        $this->pagedata['comp_data'] = $comp_data;
        $this->pagedata['clearingtable'] = $clearingtable;


        list($usec, $sec) = explode(" ", microtime());
        echo date('Y-m-d H:i:s', $sec) . " " . $usec . "<hr/>";


        $this->page('analysis/lmreport/reportshow_test.html');
    }

    function logist_cost()
    {
        $where = array('active' => 'true');
        if (!empty($this->shopIds)) {
            $shopIds = $this->shopIds;
            $where['shop_id'] = $this->shopIds;
        } else {
            $shopIds = "";
        }
        $paybegin = strtotime($_POST['paybegin_date']);
        $payend = strtotime($_POST['payend_date']);

        $_POST['paybegin_date'] = $_POST['paybegin_date'] . ' ' . $_POST['_DTIME_']['H']['paybegin_date'] . ':' . $_POST['_DTIME_']['M']['paybegin_date'];
        $paybegin = strtotime($_POST['paybegin_date']);
        $_POST['payend_date'] = $_POST['payend_date'] . ' ' . $_POST['_DTIME_']['H']['payend_date'] . ':' . $_POST['_DTIME_']['M']['payend_date'];
        $payend = strtotime($_POST['payend_date']);
        $_POST['paybegin_date'] = $_POST['paybegin_date'] ? $_POST['paybegin_date'] : $paybegin_date;
        $_POST['payend_date'] = $_POST['payend_date'] ? $_POST['payend_date'] : $payend_date;
        if ($_POST['paybegin_date']) {
            $_POST['paybegin_date'] = strtotime($_POST['paybegin_date']);
            $_POST['paybegin_date'] = date("Y-m-d H:i:s", $_POST['paybegin_date']);
        }
        if ($_POST['payend_date']) {
            $_POST['payend_date'] = strtotime($_POST['payend_date']);
            $_POST['payend_date'] = date("Y-m-d H:i:s", $_POST['payend_date']);
        }
        $_POST['shop'] = $_POST['shop'] ? $_POST['shop'] : $shopIds;

        //供应商
        if ($_POST['customername']) {
            $clearingtable['customername'] = $_POST['customername'];
        }
        if ($_POST['dlyname']) {
            $clearingtable['name'] = $_POST['dlyname'];
        }
        $clearingtable['shop_id'] = $_POST['shop'];
        $shop_obj = app::get('ome')->model('shop');
        $dly_corpMdl = app::get('ome')->model('dly_corp');

        $customername_list = $shop_obj->getList('shortname,customername,shop_id', $where, 0, -1, 'shop_id asc');
        $dlyname_list = $dly_corpMdl->getList('corp_id,name', array('d_type' => 1));
        $this->pagedata['customername'] = $customername_list;
        $this->pagedata['dlyname'] = $dlyname_list;

        #统计日期
        if ($_POST['paybegin_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {

            $paybegin_date = strtotime(date("Y-m-d H:i:s", time()));
            $clearingtable['paybegin_date'] = $paybegin_date;
        } else {
            $paybegin_date = $_POST['paybegin_date'];
            $clearingtable['paybegin_date'] = $paybegin;
        }
        if ($_POST['payend_date'] == '1970-01-01 08:00:00' || !$_POST['paybegin_date']) {
            $payend_date = strtotime(date("Y-m-d H:i:s", time()));
            $clearingtable['payend_date'] = $payend_date;
        } else {
            $payend_date = $_POST['payend_date'];
            $clearingtable['payend_date'] = $payend;
        }
        $shop_obj = app::get('wms')->model('deliverycomp');
        $comp_data = $shop_obj->GetlogistSumData($_POST['customername'], $_POST['dlyname'], $paybegin_date, $payend_date);
        $this->pagedata['comp_data'] = $comp_data;
        $this->pagedata['clearingtable'] = $clearingtable;
        $this->page('analysis/lmreport/reportlogist.html');
    }

    function report_logist()
    {
        $paybegin_date = substr($_GET['paybegin_date'], 0, 10);
        $payend_date = substr($_GET['payend_date'], 0, 10);
        $where = array('active' => 'true');

        set_time_limit(600);

        $shop_obj = app::get('wms')->model('deliverycomp');
        $paybegin_date = date("Y-m-d H:i:s", $paybegin_date);
        $payend_date = date("Y-m-d H:i:s", $payend_date);
        $comp_data = $shop_obj->GetlogistSumData($_GET['customername'], $_GET['dly_type'], $paybegin_date, $payend_date);

        include_once ROOT_DIR . "/custom/lib/phpExcel.php";

        $excel = new phpExcel();
        $excel->addHeader(array(
            '客户简称', '客户全称', '快递公司'
        , '普通区域小于3KG', '普通区域小于3KG金额合计', '普通区域3KG', '普通区域3KG~5KG金额合计'
        , '普通区域大于5KG', '普通区域大于5KG金额合计', '普通区域金额合计', '特殊区域新疆', '特殊区域新疆金额合计', '特殊区域西藏', '特殊区域西藏金额合计', '特殊区域内蒙', '特殊区域内蒙金额合计', '特殊区域海南', '特殊区域海南金额合计', '特殊区域合计', '合计'
        ));
        if ($comp_data) {

            foreach ($comp_data as $val) {
                $data_xls[] = array(
                    $val['shortname'],
                    $val['customername'],
                    $val['logi_name'],
                    $val['weight_lthan3'] ? $val['weight_lthan3'] : 0,
                    $val['cost_lthan3'] ? $val['cost_lthan3'] : 0,
                    $val['weight_lthan5'] ? $val['weight_lthan5'] : 0,
                    $val['cost_lthan5'] ? $val['cost_lthan5'] : 0,
                    $val['weight_than5'] ? $val['weight_than5'] : 0,
                    $val['cost_than5'] ? $val['cost_than5'] : 0,
                    $val['common_cost'] ? $val['common_cost'] : 0,
                    $val['weight_xinjiang'] ? $val['weight_xinjiang'] : 0,
                    $val['cost_xinjiang'] ? $val['cost_xinjiang'] : 0,
                    $val['weight_neimeng'] ? $val['weight_neimeng'] : 0,
                    $val['cost_neimeng'] ? $val['cost_neimeng'] : 0,
                    $val['weight_xizang'] ? $val['weight_xizang'] : 0,
                    $val['cost_xizang'] ? $val['cost_xizang'] : 0,
                    $val['weight_hainan'] ? $val['weight_hainan'] : 0,
                    $val['cost_hainan'] ? $val['cost_hainan'] : 0,
                    $val['special_cost'] ? $val['special_cost'] : 0,
                    $val['total_cost'] ? $val['total_cost'] : 0
                );
            }
        }
        $excel->addBody(
            $data_xls
        );

        $excel->downLoad();
        exit;
    }
}
